package cn.tedu.utils;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.util.Properties;

import com.alibaba.druid.pool.DruidDataSource;

public class DBUtils {
	private static DruidDataSource ds;
	
	static {
		Properties ps = new Properties();
		InputStream is = DBUtils.class.getClassLoader().getResourceAsStream("jdbc.properties");
		try {
			ps.load(is);
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		String driver = ps.getProperty("db.driver");
		String url = ps.getProperty("db.url");
		String username = ps.getProperty("db.username");
		String password = ps.getProperty("db.password");
		String maxSize = ps.getProperty("db.maxActive");
		String initSize = ps.getProperty("db.initialSize");
		
		ds = new DruidDataSource();
		ds.setDriverClassName(driver);
		ds.setUrl(url);
		ds.setUsername(username);
		ds.setPassword(password);
		ds.setMaxActive(Integer.parseInt(maxSize));
		ds.setInitialSize(Integer.parseInt(initSize));
	}
	
	public static Connection getConn() throws Exception {
		return ds.getConnection();
	} 
}

















